package com.cisau.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cisau.entity.PrizeEntity;
import com.cisau.service.PrizeService;


import net.sf.json.JSONArray;

@Controller
@RequestMapping("/prize")
public class PrizeController {
	@Autowired
	private PrizeService service;
	
	
	@RequestMapping("/findAll")
	public void findAll(HttpServletRequest request,HttpServletResponse response) throws IOException {
		
		
		JSONArray jsonArray = JSONArray.fromObject(service.findAll());
		System.out.println(jsonArray);
		response.setCharacterEncoding("utf-8");
		response.getWriter().print(jsonArray);
	}
	@RequestMapping("/findOneById")
	public String findOneById(HttpServletRequest request,HttpServletResponse response) throws IOException {
		
		service.findOneById(request);
		return "/admin/jsp/editGift.jsp";
	}
	
	@RequestMapping("/update/update")
	public String update(PrizeEntity prize,HttpServletRequest request) throws IOException {
		System.out.println("------------"+prize.toString());
		service.update(request, prize);
		return "/admin/jsp/giftList.jsp";
	}
}
